//  this library.
import 'package:hktk_app/model/practice/practice_model.dart';


sealed class LeafChapterOrVideo{}
class LeafVideo implements LeafChapterOrVideo{}

/// 章节模型，改造，手动创建树结构(递归组件一般需求)
class ChapterModel implements  LeafChapterOrVideo{
  String? createdTime;
  String? modifyTime;
  String? createdBy;
  String? modifyBy;
  String? id;
  String? name;
  String? serverName;
  String? parentId;

  // 叶子节点标志
  bool? leaf;
  int? categoryId;
  int? sort;
  String? remark;
  int? qcount;
  String? categoryName;
  List<String>? questionIds;

  // 免费标志
  bool? free;
  String? parent;
  List<String>? children;
  List<ContentPractice>? content;
  int? level;
  String? opath;
  bool? top;
  String? topParentId;

  // 做题数量
  int? ztNum;

  // 树形节点需求
  List<ChapterModel>? treeChildren;
  bool treeStatus=true;

  ChapterModel({
    this.createdTime,
    this.modifyTime,
    this.createdBy,
    this.modifyBy,
    this.id,
    this.name,
    this.serverName,
    this.parentId,
    this.leaf,
    this.categoryId,
    this.sort,
    this.remark,
    this.qcount,
    this.categoryName,
    this.questionIds,
    this.free,
    this.parent,
    this.children,
    this.content,
    this.level,
    this.opath,
    this.top,
    this.topParentId,
    this.ztNum = 0,
  });

  ChapterModel.fromJson(Map<String, dynamic> json) {
    createdTime = json['createdTime'];
    modifyTime = json['modifyTime'];
    createdBy = json['createdBy'];
    modifyBy = json['modifyBy'];
    id = json['id'];
    name = json['name'];
    serverName = json['serverName'];
    parentId = json['parentId'];
    leaf = json['leaf'];
    categoryId = json['categoryId'];
    sort = json['sort'];
    remark = json['remark'];
    qcount = json['qcount'];
    categoryName = json['categoryName'];
    if (json["questionIds"] != null) {
      questionIds = json['questionIds'].cast<String>();
    }
    free = json['free'];
    parent = json['parent'];
    if (json["children"] != null) {
      children = json['children'].cast<String>();
    }
    if (json['content'] != null) {
      content = <ContentPractice>[];
      json['content'].forEach((v) {
        content!.add(ContentPractice.fromJson(v));
      });
    }
    level = json['level'];
    opath = json['opath'];
    top = json['top'];
    topParentId = json['topParentId'];
    ztNum = 0;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['createdTime'] = createdTime;
    data['modifyTime'] = modifyTime;
    data['createdBy'] = createdBy;
    data['modifyBy'] = modifyBy;
    data['id'] = id;
    data['name'] = name;
    data['serverName'] = serverName;
    data['parentId'] = parentId;
    data['leaf'] = leaf;
    data['categoryId'] = categoryId;
    data['sort'] = sort;
    data['remark'] = remark;
    data['qcount'] = qcount;
    data['categoryName'] = categoryName;
    data['questionIds'] = questionIds;
    data['free'] = free;
    data['parent'] = parent;
    data['children'] = children;
    if (content != null) {
      data['content'] = content!.map((v) => v.toJson()).toList();
    }
    data['level'] = level;
    data['opath'] = opath;
    data['top'] = top;
    data['topParentId'] = topParentId;
    return data;
  }
}
